package pack0820;

//StringBuffer 内容可变，长度可变的字符序列
//StringBuilder 内容可变，长度可变的字符串
public class DemoA {
    //StringBuffer和StringBuilder的新建
    public static void a(){
        StringBuilder ss = new StringBuilder();
        StringBuffer str1 = new StringBuffer();
        StringBuffer str2 = new StringBuffer("abc");
        StringBuffer str3 = new StringBuffer("abc");
        System.out.println(str2==str3);
    }
    //StringBuffer的结尾处链接一个新的字符串；append
    public static void b(){
        StringBuffer s = new StringBuffer("abc");
        s.append("sdf");//在原有的字符串结尾处追加一个内容
        String s1 = "abc";
        s1.concat("123");//让s1和新的字符串连接起来，s1的内容没有改变
        System.out.println(s);
        System.out.println(s1);
    }
    //在原有字符指定位置处插入新的内容 insert
    //删除指定范围内的字符串 delete
    //将字符串反转过来
    public static void c(){
        StringBuffer s = new StringBuffer("asdfgh");
        s.insert(2,"147");
        System.out.println(s);
        s.delete(2,6);
        System.out.println(s);
        s.reverse();
        System.out.println(s);
    }
    //Stirng和StirngBuffer类型之间的转换
    public static void d(){
        String s = "asd";
        StringBuffer s1 = new StringBuffer(s);

        String s2 = s1.toString();
        System.out.println(s);
        System.out.println(s1);
        System.out.println(s2);
    }

    public static void main(String[] args) {
        d();
    }

}
